home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / Restore Screen Cluts / WindowPositioner.h < prev   
Encoding:
C/C++ Source or Header  |  1993-01-18  |  6.9 KB  |  149 lines  |  [TEXT/MPS ]

  1. #ifndef __WINDOWPOSITIONER__
  2. #define __WINDOWPOSITIONER__
  3. /******************************************************************************\
  4. *
  5. * Apple Macintosh Developer Technical Support
  6. *
  7. * Window-handling code for the ColorReset application
  8. *
  9. * Program: ColorReset
  10. * File:    WindowHandler.h
  11. *
  12. * by:      Forrest Tanaka
  13. *
  14. * Copyright © 1988-1992 Apple Computer, Inc.
  15. * All rights reserved.
  16. *
  17. \******************************************************************************/
  18.  
  19.  
  20. /******************************************************************************\
  21. * Header Files
  22. \******************************************************************************/
  23.  
  24. #ifndef THINK_C
  25. #ifndef __WINDOWS__
  26. #include <Windows.h>
  27. #endif
  28. #endif
  29.  
  30.  
  31. /******************************************************************************\
  32. * Constants
  33. \******************************************************************************/
  34.  
  35. #define kMainScreenPos   0 /* Position window against the main screen */
  36. #define kParentPos       1 /* Position window against parent window */
  37. #define kParentScreenPos 2 /* Position window against parent window’s screen */
  38.  
  39. #define kCenterPos  0 /* Position window centered on base rectangle */
  40. #define kAlertPos   1 /* Position window in alert position */
  41. #define kStaggerPos 2 /* Position window staggered from other windows */
  42.  
  43.  
  44. /******************************************************************************\
  45. * PositionScreenRect - Position a rectangle based on the screen set-up
  46. *
  47. * Whenever a window is to be positioned on a screen in an aesthetic or at least
  48. * unannoying way, PositionScreenRect is called to calculate a position for the
  49. * window that tries not to get on people’s nerves.  The position is returned as
  50. * a point in global coordinates at which the top-left corner of the portRect of
  51. * of the window being positioned should be placed.  The screenOption parameter
  52. * specifies which screen the window should appear on.  It has the following
  53. * values and meanings:
  54. *
  55. * kMainScreenPos   - Always position the window somewhere on the main screen.
  56. *
  57. * kParentPos       - Position the window within the portRect of the window
  58. *                    specified by parentWindow.  If parentWindow is nil, then
  59. *                    this parameter defaults to kMainScreenPos.
  60. *
  61. * kParentScreenPos - Position the window on the screen that contains most of the
  62. *                    area of the window specified by parentWindow.  If
  63. *                    parentWindow is nil or if Color QuickDraw isn’t available,
  64. *                    then this parameter defaults to kMainScreenPos.
  65. *
  66. * The positionOption parameter specifies how the window is to be positioned
  67. * within the screen (or parentWindow if screenOption == kParentPos).  It has the
  68. * following values and meanings:
  69. *
  70. * kCenterPos  - Center the window
  71. *
  72. * kAlertPos   - Position the window in alert position, that is, 1/3 of the
  73. *               screen is above the alert and 2/3 below it.
  74. *
  75. * kStaggerPos - Stagger the window from existing windows.  An attempt is made to
  76. *               position the window so that its portRect is in the upper-left
  77. *               corner of the screen (or parentWindow if screenOption ==
  78. *               kParentPos).  If the top-left corner of one or more windows is
  79. *               already in that general area, then another attempt is made down
  80. *               and to the right a bit.  These attempts are made either until
  81. *               an area that doesn’t collide with an existing window is found or
  82. *               no areas devoid of windows can be found.  If no free area was
  83. *               found, then attempts are made from the top-left corner again,
  84. *               but this time collisions are tolerated.  A position that has the
  85. *               fewest number of collisions is returned.
  86. *
  87. * The portRect of the window being positioned is normally passed in the
  88. * windowRect parameter.  Its actual coordinates don’t matter; PositionScreenRect
  89. * is only interested in its width and height.  If positionOption == kStaggerPos,
  90. * then PositionScreenRect won’t allow the portRect of a window to be staggered
  91. * right off of the screen or window it’s being positioned in.  If it’s OK for a
  92. * window to be staggered partly off of a screen or if the final size of the
  93. * window depends on the position that PositionScreenRect returns, then
  94. * windowRect should specify the smallest rectangle that would be allowed to be
  95. * visible when the window is placed at the location that PositionScreenRect
  96. * returns.  In other words, if you want PositionScreenRect to guarantee that at
  97. * least the top-left 100 x 100 pixels of the window being positioned are visible
  98. * when it’s placed at the location that PositionScreenRect returns, then
  99. * windowRect should be 100 x 100 pixels.
  100. *
  101. * parentWindow specifies the window that the positioned window is based on.  See
  102. * the description of the screenOption parameter for details.  If screenOption ==
  103. * kMainScreen, then parentWindow is ignored.
  104. *
  105. * hBias and vBias are only used if positionOption == kStaggerPos.  They specify
  106. * the horizontal and vertical amounts to offset the returned position.  The
  107. * number of pixels between the top of the portRect of the window being
  108. * positioned and the top of the window’s frame should be passed in vBias.
  109. * Likewise, the number of pixels between the left edge of the window’s portRect
  110. * and the left edge of the window’s frame should be passed in hBias.  This is
  111. * normally used to take into account the amount of space taken up by the title
  112. * bar of the window being positioned.  You can use CalcWindowBias to have the
  113. * bias calculated for you.
  114. \******************************************************************************/
  115.  
  116. void PositionScreenRect(
  117.     Rect      *modWindowRect,
  118.     short     screenOption,
  119.     short     positionOption,
  120.     WindowPtr parentWindow,
  121.     short     hBias,
  122.     short     vBias);
  123.  
  124.  
  125. /******************************************************************************\
  126. * CalcWindowBias - Calculate the bias for a specific kind of window
  127. *
  128. * This routine calculates and returns the bias for the kind of window whose
  129. * window proc ID is given in the procID parameter.  The bias’s horizontal
  130. * coordinate can then be passed in the hBias parameter of PositionScreenRect and
  131. * the vertical coordinate can be passed in the vBias parameter.  This is so that
  132. * windows can be staggered while taking into account the size of the title bar
  133. * of a window and other parts of the window frame.  The "bias" is just my
  134. * (actually Craig’s) word for the vertical and horizontal distance between the
  135. * top-left coordinate of the rgnBBox of the content region of a window and the
  136. * top-left coordinate of the rgnBBox of the structure region of that same
  137. * window.
  138. *
  139. * If the window being positioned has a go-away box, then true is passed in the
  140. * goAwayFlag parameter, otherwise false is passed.
  141. \******************************************************************************/
  142.  
  143. Point CalcWindowBias(
  144.     short   procID,
  145.     Boolean goAwayFlag);
  146.  
  147.  
  148. #endif
  149.